﻿Imports Newtonsoft.Json

''' <summary>
''' Class to keep track of Course information
''' </summary>
''' <remarks></remarks>
<JsonObject(MemberSerialization.OptOut)> _
Public Class Course
    Public Property name As String
    Public Property notes As String
    Public Property assignments As List(Of Assignment)
    Public Property color As Color
    Public Property classRoom As String ' Planned for RC 1.3
    Public Property classHours As List(Of HourSpan) ' Planned for RC 1.3
    Public Property grade As Double ' Planned for RC 2.0
    Public Property guid As String

    ' This essentially says "Hey, don't serialize/deserialize me"
    <JsonIgnore()> _
    Public Property parent As Professor

    ' Lazy James is lazy at programming and passes data around in weird ways
    <JsonIgnore()> _
    Public Shared professorList As List(Of Professor)
    <JsonIgnore()> _
    Public Shared courseList As List(Of Course)
    <JsonIgnore()> _
    Public Shared courseEditMenu As MenuItem
    <JsonIgnore()> _
    Public Shared courseDeleteMenu As MenuItem

    Public Event created(ByRef e As Course)

    Public Sub New()
        ' set object's GUID. Add checking here at some point?
        guid = String.Concat("_", System.Guid.NewGuid().ToString("N"))
        name = "New Course"
        notes = ""
        assignments = New List(Of Assignment)
        color = Colors.LightGray
        classRoom = ""
        classHours = New List(Of HourSpan)
        grade = 0
    End Sub

    Public Sub Edit()
        Dim form As New EditCourse(Me)
        form.ShowDialog()
        If form.Response = MessageBoxResult.OK Then
            parent.courses.Remove(Me)
            parent = professorList(form.courseProfessor.SelectedIndex)
            parent.courses.Add(Me)
            form.Close()
            For Each task As Assignment In assignments
                task.callChangedParentCourseName()
            Next
        Else
            form.Close()
        End If
    End Sub

    Public Sub Create()
        Dim form As New EditCourse(Me)
        form.ShowDialog()
        If form.Response = MessageBoxResult.OK Then
            parent = professorList(form.courseProfessor.SelectedIndex)
            parent.courses.Add(Me)
            RaiseEvent created(Me)
            form.Close()
        Else
            form.Close()
        End If
    End Sub

    Public Sub Delete()
        parent.courses.Remove(Me)
        courseList.Remove(Me)
    End Sub
End Class
